// specobj.txt 

// A very simple and important script. When the object is used,
// triggers a hardcoded special encounter

// Cell 0 - 
// Cell 1,2 - A stuff done flag. if non-zero, is smashes
// 3  golems group to spawn

beginobjectscript; // talking object

variables;

short spawner = 0;
short last_abil;
short is_active = 0;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();
	set_obj_act_at_dist(ME,1);
	break;

beginstate DEAD_STATE;
	break;

beginstate START_STATE; 
	if (gf(308,0) > 0) {
		sf(get_memory_cell(1),get_memory_cell(2),1);
		end();
		}
	if (get_sdf(get_memory_cell(1),get_memory_cell(2)) > 0) 
		end();
		
	if (is_active == 0) {
		if (get_nearest_good_char(8) >= 0) {
			is_active = 1;
			print_str_color("A power crystal nearby has sensed your presence. It begins to shoot out sparks.",2);
			play_sound(197);
			}
			else end();
		}

	if ((get_nearest_good_char(4) >= 0) && (get_sdf(get_memory_cell(1),get_memory_cell(2)) == 0)) {
		if ((get_memory_cell(2) < 14) && (gf(60,22) > 0))
			end();
		if ((get_memory_cell(2) == 15) && (gf(60,21) > 0))
			end();
		if ((get_memory_cell(2) == 16) && (gf(60,21) > 0))
			end();
			
		sf(get_memory_cell(1),get_memory_cell(2),1);	
		run_sparkles_on_object(ME,174,1,4);
		print_str_color("The crystal flashes with light. Several golems emerge from a nearby vat.",2);
		
		
		activate_hidden_group(get_memory_cell(3));
		set_summon_level(30000 + get_memory_cell(3),1);
		place_particle_num(30000 + get_memory_cell(3),1051,1,8);

		if (get_memory_cell(2) == 12)
			set_new_abil(30000 + get_memory_cell(3),2);
		if (get_memory_cell(2) == 13)
			set_new_abil(30000 + get_memory_cell(3),36);
		if (get_memory_cell(2) == 14)
			set_new_abil(30000 + get_memory_cell(3),5);
		if (get_memory_cell(2) == 15)
			set_new_abil(30000 + get_memory_cell(3),6);
		if (get_memory_cell(2) == 16)
			set_new_abil(30000 + get_memory_cell(3),12);
		if (get_memory_cell(2) == 17)
			set_new_abil(30000 + get_memory_cell(3),16);
		if (get_memory_cell(2) == 18)
			set_new_abil(30000 + get_memory_cell(3),20);
		if (get_memory_cell(2) == 19) {
			set_boss_level(30000 + get_memory_cell(3),1);
			set_new_abil(30000 + get_memory_cell(3),37);
			}
		
		if (gf(33,22) == 1) {
			print_str_color("  They aren't fully charged.",2);
			force_char_status(30000 + get_memory_cell(3),5,8);
			}
		if (gf(33,22) == 2) {
			print_str_color("  They've been charged with extra energy.",2);
			force_char_status(30000 + get_memory_cell(3),2,8);
			}
		if (gf(60,25) == 0) {
			sf(60,25,1);
			ok_dlog(46,2);
			}
		}
	break;

beginstate RUN_ANIM_STATE;
	if ((get_sdf(get_memory_cell(1),get_memory_cell(2)) == 0) && (get_ran(1,0,100) < 16) && (is_active > 0)) 
		run_sparkles_on_object(ME,100,8,3);
		
		
	break;

beginstate USE_STATE;
	if (get_sdf(get_memory_cell(1),get_memory_cell(2)) > 0) {
		print_str_color("The crystal is now cracked and useless.",2);
		end();
		}
	run_special(get_memory_cell(2));
break;
